package cn.tedu.review;

import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Objects;

public class TestObject {
    public static void main(String[] args) {
        Cat c1=new Cat();
        Cat c2=new Cat();
        Cat c3=new Cat("喵喵",3,99.9);
        Cat c4=new Cat("喵喵",3,99.9);

        System.out.println(c1==c2);//F
        System.out.println(c3==c4);//F
        System.out.println(c1==c4);//F

        System.out.println(c1.equals(c2));//t
        System.out.println(c3.equals(c4));//t
        System.out.println(c1.equals(c4));//f

        System.out.println(c1);
        System.out.println(c4);
                                           //地址值   //参数
        System.out.println(c1.hashCode());//460141958//29731
        System.out.println(c2.hashCode());//1163157884//29731
        System.out.println(c3.hashCode());//1956725890//33121119
        System.out.println(c4.hashCode());//356573597//33121119

        String s1="abc";
        char[] v={'a','b','c'};
        String s2=new String(v);
        String s3="aaa";

        System.out.println(s1==s2);//f
        System.out.println(s1==s3);//f

        System.out.println(s1);//abc
        System.out.println(s2);//abc

        System.out.println(s1.equals(s2));//t
        System.out.println(s1.equals(s3));//f

        byte[] bs=s2.getBytes(StandardCharsets.UTF_8);
        System.out.println(Arrays.toString(bs));

    }
}
class Cat{
    String name;
    int age;
    double price;

    public Cat() {
    }

    public Cat(String name, int age, double price) {
        this.name = name;
        this.age = age;
        this.price = price;
    }

    /*@Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Cat cat = (Cat) o;
        return age == cat.age && Double.compare(cat.price, price) == 0 && Objects.equals(name, cat.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, age, price);
    }*/

    @Override
    public String toString() {
        return "Cat{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", price=" + price +
                '}';
    }
}
